<template>
  <div>

  </div>
</template>

<script>
  export default {
    data() {
      return {
        
      }
    },
    mounted() {
      this.get_code();
    },
    methods: {
			//用户授权
			get_code() {
        let that = this;
        let openid = that.$route.query.openid;
        let access_token = that.$route.query.access_token;
        let login_style = that.$route.query.login_style;
        let openidstatus = 1;
        window.localStorage.setItem('openid', openid);
        window.localStorage.setItem('wx_token', access_token);
        console.log('打印',openid,access_token,login_style,openidstatus);
         
        if(login_style == 'login') {
          
          that.$post(that.$path+'/index.php/api/formal/VerificationLogin/login',{openid,openidstatus}).then((response) => {
              if(response.code == 200) {
                  window.localStorage.setItem('access_token',response.data.access_token);
                  window.localStorage.setItem('timer', Date.now());

                  let userInfo = JSON.stringify(response.data.data);
                  window.localStorage.setItem('userInfo', userInfo);

                  //user_company_status  0是未绑定  1是已绑定  2是已有企业但未认证 3加入他人企业未通过
                  if(response.data.data.user_company_status == 1) {
                      that.$openTips({
                        text: '登录成功',
                        time: 1000
                      })
                      that.$router.push({path:'/userCenter'});
                  }
                  else if(response.data.data.user_company_status == 2) {
                    that.$openDialog({
                      src: require('../common/images/UI-10.png'),
                      title: '欢迎您',
                      message: '为了更好的使用本平台',
                      messagemore: '您需要绑定您目前就职或创办的企业',
                      okText: '立即绑定',
                      callback (flag) {
                        if(flag) {
                          that.$router.push({path:'/Certification'});
                        }else {
                          that.$router.push({path:'/userCenter'});
                        } 
                      }
                    });
                  }else if(response.data.data.user_company_status == 3) {
                      that.$openDialog({
                          src: require('../common/images/UI-10.png'),
                          title: '登录成功',
                          message: '请等待审核完成',
                          okText: '完成',
                          callback (flag) {
                              if(flag) {
                                  that.$router.push({path:'/userCenter'});
                              }  
                          }
                      });
                  }else if(response.data.exist == '') {
                       that.$router.push({path:'/bingIphone'});
                  }else {
                    that.$openDialog({
                      src: require('../common/images/UI-10.png'),
                      title: '欢迎您',
                      message: '为了更好的使用本平台',
                      messagemore: '您需要绑定您目前就职或创办的企业',
                      okText: '立即绑定',
                      cancelText: '暂时跳过',
                      callback (flag) {
                          if(flag) {
                            that.$router.push({path:'/companyCreate'});
                          }else {
                            that.$router.push({path:'/userCenter'});
                          }     
                      }
                    });
                  }



              }else{ 
                  this.$openTips({
                      text: response.data.msg,
                      time: 2000
                  })
                  return false;
              }
          })
        }else if(login_style == 'register') {
           
          that.$router.push({path:'/bingIphone'});
        }
			},
    }
  }
</script>

<style>

</style>